package wzr;
import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.*;

import mainWindow.MainFrame;

import DataBase.*;
public class VerbSenseBlock extends SenseBlock
{
	public VerbSenseBlock(VerbSense vs, boolean hl, int num)
	{
		super(vs, hl, num);
		verbSense = vs;
		initVerb();
	}
	private VerbSense verbSense;
	void initVerb()
	{
		if (verbSense.hasAntonyms())
		{
			Box antonymsPanel = Box.createVerticalBox();
			//antonymsPanel.setLayout(new BoxLayout(antonymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getAntonyms().size()];
			for (int i = 0; i < verbSense.getAntonyms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getAntonyms().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getAntonyms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getAntonyms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				antonymsPanel.add(str[i]);
			}
			antonymsPanel.add(Box.createVerticalGlue());
			antonymsPanel.setBackground(null);
			antonymsPanel.setOpaque(false);
			relation.addTab("Antonyms", antonymsPanel);
		}
		if (verbSense.hasHypernyms())
		{
			Box hypernymsPanel = Box.createVerticalBox();
			//hypernymsPanel.setLayout(new BoxLayout(hypernymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getHypernyms().size()];
			for (int i = 0; i < verbSense.getHypernyms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getHypernyms().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getHypernyms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getHypernyms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				hypernymsPanel.add(str[i]);
			}
			hypernymsPanel.add(Box.createVerticalGlue());
			hypernymsPanel.setBackground(null);
			hypernymsPanel.setOpaque(false);
			relation.addTab("Hypernyms", hypernymsPanel);
		}
		if (verbSense.hasTroponyms())
		{
			Box troponymsPanel = Box.createVerticalBox();
			//troponymsPanel.setLayout(new BoxLayout(troponymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getTroponyms().size()];
			for (int i = 0; i < verbSense.getTroponyms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getTroponyms().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getTroponyms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getTroponyms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				troponymsPanel.add(str[i]);
			}
			troponymsPanel.add(Box.createVerticalGlue());
			troponymsPanel.setBackground(null);
			troponymsPanel.setOpaque(false);
			relation.addTab("Troponyms", troponymsPanel);
		}
		if (verbSense.hasCoordinateTerms())
		{
			Box coordinatePanel = Box.createVerticalBox();
			//coordinatePanel.setLayout(new BoxLayout(coordinatePanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getCoordinateTerms().size()];
			for (int i = 0; i < verbSense.getCoordinateTerms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getCoordinateTerms().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getCoordinateTerms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getCoordinateTerms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				coordinatePanel.add(str[i]);
			}
			coordinatePanel.add(Box.createVerticalGlue());
			coordinatePanel.setBackground(null);
			coordinatePanel.setOpaque(false);
			relation.addTab("Coordinate Terms", coordinatePanel);
		}
		if (verbSense.hasDevirations())
		{
			Box derivationsPanel = Box.createVerticalBox();
			//derivationsPanel.setLayout(new BoxLayout(derivationsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getDerivations().size()];
			for (int i = 0; i < verbSense.getDerivations().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getDerivations().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getDerivations().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getDerivations().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				derivationsPanel.add(str[i]);
			}
			derivationsPanel.add(Box.createVerticalGlue());
			derivationsPanel.setBackground(null);
			derivationsPanel.setOpaque(false);
			relation.addTab("Derivations", derivationsPanel);
		}
		if (verbSense.hasEntails())
		{
			Box entailsPanel = Box.createVerticalBox();
			//entailsPanel.setLayout(new BoxLayout(entailsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getEntails().size()];
			for (int i = 0; i < verbSense.getEntails().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getEntails().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getEntails().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getEntails().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				entailsPanel.add(str[i]);
			}
			entailsPanel.add(Box.createVerticalGlue());
			entailsPanel.setBackground(null);
			entailsPanel.setOpaque(false);
			relation.addTab("Entails", entailsPanel);
		}
		if (verbSense.hasCauses())
		{
			Box causesPanel = Box.createVerticalBox();
			//causesPanel.setLayout(new BoxLayout(causesPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getCauses().size()];
			for (int i = 0; i < verbSense.getCauses().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getCauses().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getCauses().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getCauses().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				causesPanel.add(str[i]);
			}
			causesPanel.add(Box.createVerticalGlue());
			causesPanel.setBackground(null);
			causesPanel.setOpaque(false);
			relation.addTab("Causes", causesPanel);
		}
		if (verbSense.hasVerbGroups())
		{
			Box groupsPanel = Box.createVerticalBox();
			//antonymsPanel.setLayout(new BoxLayout(antonymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getVerbGroups().size()];
			for (int i = 0; i < verbSense.getVerbGroups().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getVerbGroups().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getVerbGroups().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getVerbGroups().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				groupsPanel.add(str[i]);
			}
			groupsPanel.add(Box.createVerticalGlue());
			groupsPanel.setBackground(null);
			groupsPanel.setOpaque(false);
			relation.addTab("Verb Groups", groupsPanel);
		}
		if (verbSense.hasAlsoSees())
		{
			Box alsoseesPanel = Box.createVerticalBox();
			//alsoseesPanel.setLayout(new BoxLayout(alsoseesPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[verbSense.getAlsosees().size()];
			for (int i = 0; i < verbSense.getAlsosees().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[verbSense.getAlsosees().get(i).get_Words().size()];
				for (int j = 0; j < verbSense.getAlsosees().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(verbSense.getAlsosees().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				alsoseesPanel.add(str[i]);
			}
			alsoseesPanel.add(Box.createVerticalGlue());
			alsoseesPanel.setBackground(null);
			alsoseesPanel.setOpaque(false);
			relation.addTab("Also see", alsoseesPanel);
		}
		if (verbSense.hasTopics() || verbSense.hasRegions() || verbSense.hasUsages())
		{
			JTextPane domainPane = new JTextPane();
			domainPane.setBackground(null);
			domainPane.setOpaque(false);
			domainPane.setEditable(false);
			String tmp = new String("");
			if (verbSense.hasTopics())
			{
				tmp += "Topic: ";
				for (int i = 0; i < verbSense.getTopics().size(); i ++)
				{
					for (int j = 0; j < verbSense.getTopics().get(i).get_Words().size(); j ++)
					{
						if (j == verbSense.getTopics().get(i).get_Words().size() - 1)
						{
							tmp += (verbSense.getTopics().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (verbSense.getTopics().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			if (verbSense.hasRegions())
			{
				tmp += "Region: ";
				for (int i = 0; i < verbSense.getRegions().size(); i ++)
				{
					for (int j = 0; j < verbSense.getRegions().get(i).get_Words().size(); j ++)
					{
						if (j == verbSense.getRegions().get(i).get_Words().size() - 1)
						{
							tmp += (verbSense.getRegions().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (verbSense.getRegions().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			if (verbSense.hasUsages())
			{
				tmp += "Usage: ";
				for (int i = 0; i < verbSense.getUsages().size(); i ++)
				{
					for (int j = 0; j < verbSense.getUsages().get(i).get_Words().size(); j ++)
					{
						if (j == verbSense.getUsages().get(i).get_Words().size() - 1)
						{
							tmp += (verbSense.getUsages().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (verbSense.getUsages().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			domainPane.setText(tmp);
			relation.addTab("Domain", domainPane);
		}
	}
}
